import React from 'react';
import { useNavigate } from 'react-router-dom';
import { getPathRoot, hasPathRoot } from '@/utils';

const RedriectPage: React.FC = () => {
  const navigate = useNavigate();
  React.useEffect(() => {
    const pathname = window.location.pathname;
    if (!hasPathRoot(pathname)) window.location.href = '/404';
    if (pathname.indexOf('/teacher/') !== -1) {
      navigate(`${getPathRoot()}/onboarding`);
    }
    if (pathname.indexOf('/unit/') !== -1) {
      navigate(`${getPathRoot()}/school`);
    }
    if (pathname.indexOf('/student/') !== -1) {
      navigate(`${getPathRoot()}/newstudent`);
    }
  }, []);
  return <></>;
};

export default RedriectPage;
